package com.suql.kotlin.activity

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.webkit.PermissionRequest
import android.widget.Toast
import com.suql.kotlin.R
import com.suql.kotlin.Singleton
import com.suql.kotlin.utils.FileUtil
import kotlinx.android.synthetic.main.activity_main.*
import org.jetbrains.anko.*
import java.security.Permission

class MainActivity : BaseActivity(), BaseActivity.PermissionCallback {
    override fun onGranted() {

        FileUtil.saveFile("123456", "kotlin-log.txt")
    }

    private val TAG: String = MainActivity::class.java.simpleName
//    private lateinit var btnKotlin: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        tvKotlin.text = "My first kotlin project"
//        verticalLayout {
//            val name = editText()
//            var bth = button("点我") {
//                onClick {
//                    toast("点到我了，${name.text}")
//                }
//            }
//        }
        btnKotlin.onClick {
            when(it!!.id) {
//                R.id.btnKotlin -> Toast.makeText(this, "Hello world, ${btnKotlin.text}", Toast.LENGTH_SHORT).show()
                R.id.btnKotlin -> {
//                    startActivity(Intent(this, SecondActivity::class.java))
//                    shortToast("点击了")
//                    Singleton.getInstance().test(this@MainActivity)
                    checkPermission(this)
                }
                else -> Log.e(TAG, "UnKnown")
            }
        }
    }

    fun AppCompatActivity.shortToast(message: String) {
        Toast.makeText(this@MainActivity, message, Toast.LENGTH_SHORT).show()
    }
}
